Fall back to nextflow_schema.json types for CLI param coercion#7108
Fall back to nextflow_schema.json types for CLI param coercion#7108ewels wants to merge 1 commit intonextflow-io:masterfrom
nextflow_schema.json types for CLI param coercion#7108Conversation
Under syntax parser v2, CLI params arrive as strings unless the pipeline declares typed params in main.nf or non-null defaults in nextflow.config. This breaks pipelines moving to v26.04.0 that rely on type-coerced params (e.g. numeric comparisons on `params.max_cpus`). When a `nextflow_schema.json` lives next to main.nf, read property types from it and coerce CLI string values before they reach ConfigBuilder. Coercion is best-effort: missing or malformed schemas are ignored, and values that don't match a declared type are left untouched. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Signed-off-by: Phil Ewels <phil.ewels@seqera.io>
✅ Deploy Preview for nextflow-docs-staging canceled.
|
nextflow_schema.json types for CLI param coercion
Note: duplication with the language serverNote that the Nextflow language server already has equivalent schema-walking code:
The right consolidation is to lift the schema-walking into the shared
Both repos would agree on what counts as a property and which keys the schema is searched under. If you like, I can re-shape this PR to put the schema reader in |
| static Map<String,String> readSchemaTypes(Path schemaFile) { | ||
| try { | ||
| final root = new JsonSlurper().parse(schemaFile) | ||
| final types = new LinkedHashMap<String,String>() |
There was a problem hiding this comment.
The types keyword can also be a list of multiple types, how would you handle that case?
Summary
Under syntax parser v2 (default in 26.04.0), CLI params arrive as strings. Unless the pipeline declares typed params in
main.nfor non-nulldefaults innextflow.config, those values stay as strings — which breaks param logic that expects e.g. numeric comparison onparams.max_cpus.This change reads property types from
nextflow_schema.json(the nf-core convention) when it sits next tomain.nf, and uses them to coerce CLI string values before they reachConfigBuilder. Pipelines that already had a schema get typed params for free with nomain.nfchanges.nextflow.config.SchemaParamsHelperCmdRun.run(), immediately afterparsedParams()propertiesblocks at the top level and underdefinitions/\$defs/allOf/oneOf/anyOfstring/integer/number/boolean(anything else left untouched)NF.isSyntaxParserV2()and respectsNXF_DISABLE_PARAMS_TYPE_DETECTIONparams { }in main.nfParamsDslTest plan
SchemaParamsHelper(12 cases: flat schema, nesteddefinitions/\$defs/allOf, coercion of all four JSON Schema types, malformed schema, missing schema, mixed-case booleans, duplicate-name first-wins,NXF_DISABLE_PARAMS_TYPE_DETECTIONopt-out, syntax parser v1 opt-out, pre-typed values from params files, typeless property)nextflow_schema.jsonconfirms--max_cpus 8 --skip_qc TRUE --ratio 0.5arrive asInteger/Boolean/FloatCmdRunTest,ParamsDslTest, and config parser v2 tests still pass🤖 Generated with Claude Code